#include <stdio.h>
#include <memory.h>

int main( )
{
    int t;
    scanf("%d", &t);
    int f[ 10001 ], p[ 501 ], w[ 501 ];
    while ( t-- )
    {
        int m, m2, i, j, n;
        scanf("%d%d%d", &m, &m2, &n);
        m = m2 - m;
        memset( f, 0, sizeof( f ) );
        for ( i = 0; i < n; i++ )
        {
            scanf("%d%d", &p[ i ], &w[ i ]);
            if ( f[ w[ i ] ] > p[ i ] || f[ w[ i ] ] == 0 )
                f[ w[ i ] ] = p[ i ];
        }
        for ( i = 0; i < n; i++ )
            for ( j = w[ i ] * 2; j <= m; j++ )
                if ( f[ j - w[ i ] ] )
                {
                    if ( f[ j - w[ i ] ] + p[ i ] < f[ j ] || f[ j ] == 0 )
                        f[ j ] = f[ j - w[ i ] ] + p[ i ];
                }
        if ( f[ m ] != 0 )
            printf("The minimum amount of money in the piggy-bank is %d.\n", f[ m ]);
        else
            printf("This is impossible.\n");
    }
    return 0;
}
